<template>
	<view class="news">
		<view class="news_item" v-for="item in newsList" :key="item.id">
			<view class="img">
				<image src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.aiimg.com%2Fuploads%2Fuserup%2F0909%2F2Z64022L38.jpg&refer=http%3A%2F%2Fimg.aiimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1619425831&t=9b2fc8ac1dfe1da6ffa6413d9093c60a" mode=""></image>
			</view>
			<view class="textarea">
				<text class="title">{{item.title}}</text>
				<view class="time"><text>发表时间:{{formatDate(item.add_time)}}</text><text>浏览次数:{{item.click}}</text></view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				newsList:[],
			}
		},
		methods: {
			async getNews(){
				const res = await this.$myrequest({
					url:'/api/getnewslist'
				})
				// console.log(res)
				this.newsList =res.data.message
			},
			formatDate(object){
				const newD = new Date(object)
				const y = newD.getFullYear();
				const m = newD.getMonth()+1;
				const d = newD.getDay()+1;
				return (y+'-'+m+'-'+d)
			}
		},
		onLoad(){
			this.getNews()
		}
	}
</script>

<style lang="scss">
.news_item{
	display: flex;
	height: 130rpx;
	border-bottom: 2px solid $market-color;
	padding: 10rpx;
	image{
		width: 100px;
		height: 70px;
	}
	.textarea{
		display: flex;
		width: 600rpx;
		height: 130rpx;
		margin-left: 15rpx;
		flex-direction: column;
		justify-content: space-between;
	}
	.title{
		font-size: 30rpx;
		word-break: break-all;  /* break-all(允许在单词内换行。) */
		text-overflow: ellipsis !important;
		-webkit-line-clamp: 1;
	}
	.time{
		font-size: 20rpx;
		text{
			margin-right:100rpx;
		}
		}
}
</style>
